package kr.hkit.powerjava.chapter22.work;

import java.util.ArrayList;

public class StudentManager implements DaoInterface<Student> {
	private ArrayList<Student> arList;

	
	public StudentManager() {
		arList = new ArrayList<>();
	}

	public StudentManager(ArrayList<Student> arList) {
		this.arList = arList;
	}

	public void prnList(){
		prnHeader();
		for (Student std : arList) {
			System.out.println(std);
		}
	}

	@Override
	public void additem(Student item) {
		arList.add(item);
	}

	@Override
	public Student searchStd(Student item) {
		if (arList.contains(item)){
			return arList.get(arList.indexOf(item));
		}else{
			return null;
		}
	}

	@Override
	public void updateItem(Student item) {
		arList.set(arList.indexOf(item), item);
	}

	@Override
	public void delitem(Student item) {
		if (arList.contains(item)){
			arList.remove(arList.indexOf(item));
		}else{
			System.out.println("해당 학생정보 없음!");
		}
	}

	@Override
	public void prnHeader() {
		String header = String.format("%3s\t %5s\t %4s\t %4s\t %4s\t %4s\t %5.2s","학번", "성명", "국어", "영어", "수학", "총점", "평균");
		System.out.println(header);
	}
	


}
